﻿using ReactiveUI;
using Splat;
using System;
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Linq;
using System.Text;
using System.Windows.Input;

namespace RxWPF.Views
{
    public class RoutingHostViewer : IScreen
    {
        private readonly IMutableDependencyResolver dependencyResolver;

        public RoutingState Router { get; }
        public RoutingHostViewer(IMutableDependencyResolver dependencyResolver)
        {
            Router = new RoutingState();

            this.dependencyResolver = dependencyResolver;

            RegisterParts(this.dependencyResolver);

            Router.Navigate.Execute(new RoutingViewer(this));
           
            ClearCmd = ReactiveCommand.Create(Router.NavigationStack.Clear);

            OpenView1 = ReactiveCommand.CreateFromTask
                (async () => await Router.Navigate.Execute(new RoutingViewer(this)).Select(x => Unit.Default));
        }

        public ICommand ClearCmd { get; set; }

        public ICommand OpenView1 { get; set; }

        private void RegisterParts(IMutableDependencyResolver dependencyResolver)
        {
            dependencyResolver.RegisterConstant(this, typeof(IScreen));

            dependencyResolver.Register(() => new RoutingView(), typeof(IViewFor<RoutingViewer>));
            dependencyResolver.Register(() => new RoutingView2(), typeof(IViewFor<RoutingView2er>));
        }
    }
}
